package com.you.atlas.web.home.module.screen;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.citrus.turbine.Context;
import com.you.atlas.biz.member.service.MemberBizQueryService;
import com.you.atlas.biz.place.service.NoteQueryService;
import com.you.atlas.biz.place.service.PlaceQueryService;
import com.you.member.dal.dao.BroadcastDAO;
import com.you.member.dal.dao.dataobject.BroadcastDO;
import com.you.place.dal.dao.IndexDAO;
import com.you.place.dal.dao.dataobject.IndexDO;
import com.you.place.dal.dao.dataobject.NoteDO;
import com.you.place.dal.dao.dataobject.PlaceDO;

public class Homepage {

    @Autowired
    private IndexDAO              indexDAO;

    @Autowired
    private BroadcastDAO          broadcastDAO;

    @Autowired
    private MemberBizQueryService memberBizQueryService;

    @Autowired
    private PlaceQueryService     placeQueryService;

    @Autowired
    private NoteQueryService      noteQueryService;

    @SuppressWarnings("rawtypes")
    public void execute(Context context) {

        IndexDO indexDO = indexDAO.find();
        if (indexDO == null) {
            return;
        }
        // place
        List<PlaceDO> placeList = placeQueryService.find(indexDO.toLong(indexDO.getTopRatePlaceId()));
        context.put("placeList", placeList);

        // note
        List<NoteDO> noteList = noteQueryService.find(indexDO.toLong(indexDO.getTopNoteId()));
        context.put("noteList", noteList);
//        if (noteList.size() > 2) {
//            context.put("noteList1", noteList.subList(0, 2));
//            context.put("noteList2", noteList.subList(2, noteList.size()));
//        } else {
//            context.put("noteList1", noteList.subList(0, noteList.size()));
//        }
        // member
        List memberList = memberBizQueryService.queryLateJoin();
        context.put("memberList", memberList);
        List<BroadcastDO> broadcastList = broadcastDAO.queryLast();
        context.put("broadcastList", broadcastList);
    }

}
